package com.atguigu.educms.controller;


import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-15
 */
@RestController
@CrossOrigin
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;

    //分页查询
    @ApiOperation(value = "分页查询")
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page, @PathVariable long limit){
        Page<CrmBanner> page1=new Page<>(page,limit);
        crmBannerService.page(page1,null);
        return R.ok().data("items",page1.getRecords()).data("total",page1.getTotal());
    }
    //获取Banner
    @ApiOperation(value = "获取Banner")
    @PostMapping("findBannerById/{id}")
    public R findBannerById(@PathVariable String id){

        CrmBanner crmBanner = crmBannerService.getById(id);
        return R.ok().data("item",crmBanner);
    }
    //添加
    @ApiOperation(value = "添加")
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){

        crmBannerService.save(crmBanner);
        return R.ok();
    }
    //修改
    @ApiOperation(value = "修改")
    @PutMapping("updateBannerById")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();
    }
    //删除
    @ApiOperation(value = "删除")
    @DeleteMapping("deleteBanner/{id}")
    public R deleteBanner(@PathVariable String id){

        crmBannerService.removeById(id);
        return R.ok();
    }
}

